var config = {
  PowerBy: "default", //作者
  CName: "default", //公司名称
  // root: "http://weilai9draw.haerbinapp.com/webDemo", //线上
  root: 'http://localhost:8808/',
  ossroot: "https://hygm.oss-cn-shanghai.aliyuncs.com/",
  imgroot: "https://hygm.oss-cn-shanghai.aliyuncs.com/",
  pageSize: 10,
  base: "/"
};


var AJAX = new function () {
  var _xhr,
    K = "Authorization",
    abs = null,
    t = this,
    tk = null;

  function finish(v, cb) {
    if (cb == null) return;
    var o;
    if (v && v.length > 1) {
      try {
        o = JSON.parse(v);
      } catch (e) {
        o = v;
      }
    }
    if (o && o.code < 0) {
      Comm.msg(o.msg);
    }
    if (o && o.code == 110) {
      Comm.msg("登录已过期，请重新登录", 5);
      setTimeout(function () {
        AJAX.clearTag();
        if (self == top) {
          location.href = config.base + 'login.html';
        } else {
          location.href = config.base + 'login.html';
        }
      }, 2000);
      Comm.loading(false);
      return;
    }
    cb(o);
    setTimeout(function () {
      Comm.loading(false);
    }, 500)
  }

  function ab() {
    if (abs == null) {
      abs = top.Comm.db(K);
      if (abs == null) abs = "";
    }
    return abs;
  }

  function repair(api) {
    console.log(api);
    var a = ab();
    if (true) {
      api += (api.indexOf("?") > 0 ? "&" : "?") + "&timespan=" + Math.random();
      tk = a;
    }
    return api;
  }

  function deobj(obj) {
    if (obj == null) return "";
    var s = [];
    for (var i in obj) {
      if (typeof obj[i] == typeof "") {
        if (obj[i].indexOf("%") > 0) obj[i] = obj[i].replace(/%/g, "%25");
        if (obj[i].indexOf("&") > 0) obj[i] = obj[i].replace(/\&/g, "%26");
        if (obj[i].indexOf("+") > 0) obj[i] = obj[i].replace(/\+/g, "%2B");
      }
      s.push(i + "=" + encodeURIComponent(obj[i]));
    }
    return s.join("&");
  }

  function error(code, cb) {
    Comm.loading(false);
    cb && cb({
      code: -1,
      msg: "服务器异常"
    });
  }

  function init(post, url, data, cb, asyn, isJson) {
    Comm.loading(true);
    url = t.Uri() + repair(url);
    if (asyn == null) asyn = true;
    if (isJson == null) isJson = false;
    var xhr = new XMLHttpRequest();
    if (asyn) {
      Comm.loading(true);
    }

    xhr.onreadystatechange = function () {
      if (this.readyState == 4) {
        if (this.status == 200) {
          finish(this.responseText, cb);
        } else {
          error(this.status, cb);
        }
      }
    };
    xhr.open(post ? "POST" : "GET", url, asyn);
    var ag = ab();
    if (ag)
      xhr.setRequestHeader('Authorization', ag);
    if (post && isJson) {
      data = JSON.stringify(data);
      xhr.setRequestHeader("Content-Type", "application/json");
      // console.log("post for json");
    } else if (post) {
      data = deobj(data);
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      // console.log("post for parameter");
    }
    xhr.send(data);
    Comm.loading(false);
  }

  /*----AJAX公用方法-----*/

  /*获取服务器接口根路径*/
  t.Uri = function () {
    return window["config"] && window["config"]["root"] ? config.root : "";
  };

  /*获取服务器调试页面根路径*/
  t.WebRoot = function () {
    return window["config"] && window["config"]["webroot"] ? config.webroot : "";
  };

  /*调用用户登录token*/
  t.setTag = function (a) {
    abs = a;
    Comm.db(K, abs);
  };

  /*用户登录成功*/
  t.setLogin = function (d) {
    var u = d.data.customerInfo;
    var s = d.data.storeInfo;
    AJAX.setTag(u.token);
    Comm.db("_userinfo", {
      id: u.userId,
      p: u.phone,
      status: u.status,
      headImg: s.companyLogo,
      nickname: u.nickname,
      realname: u.realname,
      phone: s.phone
    });
  };

  /*退出登录清除token*/
  t.clearTag = function () {
    Comm.db(K, null);
    Comm.db("_userinfo", null);
  };

  /*执行GET方法，一般用于从服务器获取数据，api长度尽量不超过1000字节*/
  /*执行GET方法，一般用于从服务器获取数据，api长度尽量不超过1000字节*/
  t.GET = function (api, cb, asyn, isJson) {
    init(false, api, null, cb, asyn, isJson);
  };
  /*执行POST方法，一般用于向服务器提交数据，data建议不为空*/
  t.POST = function (api, data, cb, asyn, isJson) {
    init(true, api, data, cb, asyn, isJson);
  };
  /*根据用户凭证判断用户是否登录*/
  t.isLogin = function () {
    return ab().length > 0;
  };
}();
var Comm = {
  select: {
    init: function (id, data, value, ds) {
      if (id && data) {
        cs = data;
        for (var i in cs) {
          $(id).append('<option value="' + cs[i][value] + '">' + cs[i][ds] + '</option>');
        }
        $(id).find('option:eq(1)').attr('selected', true);
      }
      Comm.form.render('select');
    }
  },
  Cookie: {
    set: function (name, value) {
      document.cookie = name + "=" + escape(value);
    },
    get: function (name) {
      var arr,
        reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
      if ((arr = document.cookie.match(reg))) return unescape(arr[2]);
      else return "";
    }
  },
  enPrice: function (v) {
    if (v == null || v == 0 || typeof (v) == 'undefined') {
      return 0;
    }

    if (v != null && v != "" && v != undefined) {
      return Number(v * 100).toFixed(0);
    }
  },
  checkPrice: function (price, type, msg) {
    var reg = /^\d+$/; //非负整数
    var reg2 = /^\+?(\d*\.\d{2})$/; //两位小数
    var reg3 = /^\d*\.{0,1}\d{0,1}$/; //一位小数
    var reg4 = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^[1-9]$)|(^\d\.[1-9]{1,2}$)|(^\d\.[0]{1}[1-9]{1}$|(^\d\.[1-9]{1}[0]{1}$)$)/;
    if (type == 1) { //非负整数
      if (!reg.test(price)) {
        Comm.msg(msg, 5);
        return true;
      }
    } else if (type == 2) { //非负两位小数
      if (!reg.test(price) && !reg2.test(price) && !reg3.test(price)) {
        Comm.msg(msg, 5);
        return true;
      }
    } else if (type == 3) { //非负一位小数
      if (!reg.test(price) && !reg3.test(price)) {
        Comm.msg(msg, 5);
        return true;
      }
    }
  },
  htmlDecode: function (text) {
    //1.首先动态创建一个容器标签元素，如DIV
    // var temp = document.createElement("div");
    // //2.然后将要转换的字符串设置为这个元素的innerHTML
    // temp.innerHTML = text;
    // var output = temp.innerText || temp.textContent;
    // temp = null;
    // return output;
    return '<div>' + text + '</div>';
  },
  htmlDecodeByRegExp: function (str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&amp;/g, "&");
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&nbsp;/g, " ");
    s = s.replace(/%26nbsp;/g, " ");
    s = s.replace(/&#39;/g, "\'");
    s = s.replace(/&quot;/g, "\"");
    return s;
  },
  checkEmpty: function (text, msg) {
    var reg = /^[ ]*$/;
    if (typeof (text) == "undefined" || reg.test(text)) {
      Comm.msg(msg, 5);
      return true;
    }
  },
  OrderType: function (d) {
    var s;
    switch (d) {
      case 0:
        s = '充值'
        break;
      case 1:
        s = '订单消费'
        break;
      case 2:
        s = '订单补差'
        break;
      case 3:
        s = '订单退款'
        break;
      case 4:
        s = '积分消费'
        break;
      default:
        s = '未知类型'
        break;
    }
    return s;
  },
  cutdate: function (s) {
    return s.substring(0, s.length - 2);
  },
  getAge: function (s) {
    var r = s.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
    if (r == null) return false;
    var d = new Date(r[1], r[3] - 1, r[4]);
    if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]) {
      var Y = new Date().getFullYear();
      return (Y - r[1]);
    }
    return ("输入的日期格式错误！");
  },
  cutfront: function (s, l) {
    return s.substring(l, s.length);
  },
  cutback: function (s, l) {
    return s.substring(0, s.length - l);
  },
  parse: function (s) {
    var o;
    try {
      o = JSON.parse(s);
    } catch (e) {
      o = s;
    }
    return o;
  },
  deData: function (s) {
    if (s && s.indexOf("/") > -1) {
      s = decodeURIComponent(s.replace(/\//g, "%"));
    }
    return Comm.parse(s);
  },
  enData: function (o) {
    return encodeURIComponent(JSON.stringify(o)).replace(/\%/g, "/");
  },
  db: function (t, v) {
    if (v == null) {
      if (arguments.length === 1) {
        return Comm.deData(Comm.Cookie.get(t));
      } else {
        Comm.Cookie.set(t, "");
      }
    } else {
      Comm.Cookie.set(t, Comm.enData(v));
    }
  },
  //调用方法Comm.OSS.getImgUrl(uri,'l');图片前缀更新方法
  OSS: {
    /*阿里云oss工具*/
    host: function (uri) {
      // return window["config"] && window.config["ossroot"] ? config.ossroot : "";
      if (uri.indexOf("wlj") >= 0) {
        return window['config'] && window.config['ossroot'] ? config.ossroot : '';
      } else {
        return window['config'] && window.config['imgroot'] ? config.imgroot : '';
      }
    },
    inithtml: function (d, cb) {
      top.Comm.laytpl(top.$("#upimgTpl").html()).render(d, function (html) {
        cb && cb(html)
      })
    },
    // showimg: function (a) {
    // 	Comm.layer.open({
    // 		type: 1,
    // 		title: '查看图片',
    // 		maxmin: true,
    // 		area: ['500px', '500px'],
    // 		shade: 0.3,
    // 		content: '<div style="text-align: center;"><img src="' + $(a).attr('src') + '" width="100%"/></div>'
    // 	})
    // },
    showimg: function (a) {
      // var img = $(a).attr('src');
      // img = img.substring(0, img.length - 3) + 400;
      // layer.open({
      //     type: 1,
      //     title: false,
      //     // maxmin: true,
      //     area: ['500px', '500px'],
      //     shade: 0.3,
      //     content: '<div style="text-align: center;"><img src="' + img + '" width="100%"/></div>'
      // })
      var x = 0.3;
      var y = 2;
      var img = $(a).attr('src');
      img = img.substring(0, img.length - 3) + 400;
      var imgs = new Image();
      imgs.src = img;
      imgs.onload = function () {
        var width = imgs.width;
        var height = imgs.height;
        console.log(width + "," + height)
        if (width > 600 || height > 600) {
          width = width * x;
          height = height * x;
        }
        if (width < 300 && height < 300) {
          width = width * y;
          height = height * y;
        }
        console.log(width + "," + height);
        layer.open({
          type: 1,
          title: false,
          // maxmin: true,
          area: [width + 'px', height + 'px'],
          shade: 0.3,
          shadeClose: true,
          content: '<div style="text-align: center;"><img src="' + img + '" width="100%"/></div>'
        })
      }
    },
    showimgByX: function (a, x, y) {
      var img = $(a).attr('src');
      img = img.substring(0, img.length - 3) + 400;
      var imgs = new Image();
      imgs.src = img;
      imgs.onload = function () {
        var width = imgs.width;
        var height = imgs.height;
        console.log(width + "," + height)
        if (width > 900 || height > 900) {
          width = width * x;
          height = height * x;
        }
        if (width < 300 && height < 300) {
          width = width * y;
          height = height * y;
        }
        console.log(width + "," + height);
        layer.open({
          type: 1,
          title: false,
          // maxmin: true,
          area: [width + 'px', height + 'px'],
          shade: 0.3,
          shadeClose: true,
          content: '<div style="text-align: center;"><img src="' + img + '" width="100%"/></div>'
        })
      }
    },
    /*oss访问地址*/
    /*
        获取图片访问地址
        uri:数据库中保存的文件地址
        type:显示类型 	取值:s|m|l
         */
    getImgUrl: function (uri, type) {
      if (uri == null) return "-----------error";
      if (uri.length >= 4 && uri.indexOf("http") > -1) return uri;
      var url = Comm.OSS.host(uri) + uri;
      if (type) {
        switch (type) {
          case "l":
            url += "/800";
            break;
          case "f":
            url += "/400";
            break;
          case "m":
            url += "/250";
            break;
          case "s":
            url += "/120";
            break;
          default:
            break;
        }
      }
      return url;
    }
  },
  //创建对象，并追加到f里面，attr:对象属性
  create: function (att, f, tag) {
    var a = document.createElement(tag ? tag : "div");
    if (att)
      for (var i in att) a[i] = att[i];
    (Comm.g(f) || document.body).appendChild(a);
    return a;
  },
  g: function (o) {
    if (typeof o == typeof {}) return o;
    return document.getElementById(o);
  },
  //尝试执行根方法
  exec: function (m) {
    if (window[m]) {
      var a = [];
      for (var i = 1; i < arguments.length; i++)
        a[i - 1] = arguments[i];
      window[m].apply(null, a);
    }
  },
  //显示加载s为需要显示的内容,s为false则表示关闭
  loading: function (s) {
    if (s) {
      layer.load();
    } else {
      layer.closeAll('loading');
    }
  },
  msg: function (msg, type) {
    Comm.layer.msg(msg, {
      icon: type
    });
  },
  price: function (v) {
    if (v == 0) {
      return v;
    }
    if (v != null && v != "" && v != undefined) {
      return (Number(v) / 100).toFixed(2);
    }
  },
  alert: function (str) {
    Comm.layer.alert(str, {
      icon: 1
    });
  },
  //confirm cb返回true,false
  confirm: function (str, cb) {
    Comm.layer.confirm(str, {
      icon: 3,
      title: "提示"
    }, function (index) {
      cb && cb(1);
      layer.close(index);
    })
  },
  //查询url参数，n:名称
  query: function (n, u) {
    var s = u;
    if (s == null) s = self.location.href;
    if (n) {
      var g = new RegExp("(\\?|&)" + n + "=([^&|#]*)");
      var r = s.match(g);
      if (r) {
        try {
          return decodeURIComponent(r[2]);
        } catch (err) {
          return unescape(r[2]);
        }

      } else return "";
    } else {
      var i = s.indexOf("?");
      if (i === -1) return "";
      return s.substr(i + 1);
    }
  },
  go: function (r) {
    location.href = r;
  },
  price: function (v) {
    if (v == null || v == 0 || typeof (v) == 'undefined') {
      return 0;
    }

    if (v != null && v != "" && v != undefined) {
      return Number(v / 100).toFixed(2);
    }
  },

  dateTimes: function (stamp) {
    var date = new Date(stamp + 8 * 3600 * 1000); // 增加8小时
    // var date = new Date(stamp);
    if (date.toJSON() == null || date.toJSON().length == 0 || stamp == 0) return '未知时间'
    return date.toJSON().substr(0, 19).replace('T', ' ');
  },

  //时间转换函数
  format: function (stamp, type) {
    type = type && type.match(/\w+/g);
    var now = new Date(stamp),
      year = now.getFullYear(),
      month = now.getMonth() + 1,
      date = now.getDate(),
      hour = now.getHours(),
      minute = now.getMinutes(),
      second = now.getSeconds(),
      o = [],
      arr = {
        yyyy: year,
        mm: check(month),
        dd: check(date),
        h: check(hour),
        m: check(minute),
        s: check(second)
      };
    if (type) {
      for (var i = 0; i < type.length; i++) {
        var tmp = type[i];
        tmp = tmp.toLocaleLowerCase();
        if (arr[type[i]])
          o.push(type[i] == "h" ? " " + arr[type[i]] : "-" + arr[type[i]]);
      }
      if (o.length) return o.join("").slice(1);
    } else
      return (
        arr.yyyy +
        "-" +
        arr.mm +
        "-" +
        arr.dd +
        " " +
        arr.h +
        ":" +
        arr.m +
        ":" +
        arr.s
      );

    function check(num) {
      if (num < 10) {
        return "0" + num;
      }
      return num;
    }
  },
  wait: 60,
  timeCountDownclick: true,
  timeCountDown: function (o, phone, type, imgcode) {
    /*发送验证码公用方法*/
    /*o 点击发送验证码按钮*/
    /*phone 发送短信手机号*/
    /*type 验证码类型*/
    /*imgcode 图片验证码，可不传*/
    /*调用 app.timeCountDown(this,15928877394,1,5421)*/
    //按钮倒计时
    imgcode = imgcode == undefined ? "" : imgcode;
    if (!phone) {
      layer.msg("请输入手机号");
      return;
    }
    var reg = /^1\d{10}$/;
    if (phone && !reg.test(phone)) {
      layer.msg("手机格式错误");
      return;
    }
    if (Comm.timeCountDownclick) {
      Comm.timeCountDownclick = false;
      o.setAttribute("disabled", true);
      AJAX.GET(
        "/api/customer/sendSMS?phone=" +
        phone +
        "&type=" +
        type +
        "&_device=" +
        1,
        function (d) {
          if (d.code == 1) {
            layer.msg("短信已发送，请注意查收");
            var i = setInterval(function () {
              if (Comm.wait == 0) {
                o.removeAttribute("disabled");
                o.value = "重新发送";
                Comm.wait = 60;
                clearInterval(i);
              } else {
                o.value = Comm.wait + "秒后重发";
                Comm.wait--;
              }
            }, 1000);
          } else {
            o.removeAttribute("disabled");
            layer.msg(d.msg);
          }
          Comm.timeCountDownclick = true;
        }
      );
    }
  },
  GetData: function (id) {
    var p = {};
    var id = id == undefined || id == "" ? "form" : id;
    $("#" + id).find("input,textarea,select").each(function (i, e) {
      if ($(e).attr("name") != undefined) {
        if ($(e).attr('laydate') != undefined) {
          p[$(e).attr("name")] = $(e).val();
        } else {
          p[$(e).attr("name")] = $(e).val();
        }
      }
    })
    return p;
  },
  SetData: function (p, id) {
    var id = id == undefined || id == "" ? "form" : id;
    $("#" + id).find("input,textarea,select").each(function (i, e) {
      if ($(e).attr("name") != undefined && $(e).attr("type") != "radio") {
        var v = p[$(e).attr("name")]
        if (void 0 !== v && null !== v && "null" !== v || (v = "")) {
          $(e).val(v);
          if (e.hasAttribute('laydate')) {
            Comm.laydateinit(e);
          }
        }
      }
    });
    return p;
  },
  uploadImg: function (btnId, imgId, divId, imgSize, isA) {
    if (imgSize == null) {
      imgSize = "max-width: 200px;max-height: 200px;";
    }
    var sfaceNum = isA == 1 ? 1 : 0;
    Comm.upload.render({
      elem: '#' + btnId, //绑定元素
      field: 'file',
      accept: 'images',
      acceptMime: 'image/jpg,image/png,image/JPEG',
      multiple: false, //单图
      url: config.ossroot,
      before: function (obj, o) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        //上传loading
        layer.load();
      },
      done: function (d) {
        sfaceNum++;
        layer.closeAll('loading'); //关闭loading
        var htmlStr1 = "<div class=\"layui-inline \">";
        htmlStr1 += "<img class=\"layui-upload-img\" src=\"" + Comm.OSS.getImgUrl(this.data.key) +
          "\" style=\"" + imgSize + "\" data=\"" + this.data.key + "\"/><br/>";
        htmlStr1 +=
          "<button type=\"button\" class=\"layui-btn layui-btn-xs layui-btn-danger\" onclick=\"$(this).parent().remove()\">删除</button></div>";
        $("#" + imgId).val(this.data.key);
        if (sfaceNum > 1) {
          $("#" + divId).html(htmlStr1);
        } else {
          $("#" + divId).append(htmlStr1);
        }
      },
      error: function () {
        //请求异常回调
        layer.closeAll('loading'); //关闭loading
      }
    });
  },
  uploadImgs: function (btnId, imgId, divId, imgSize) {
    if (imgSize == null) {
      imgSize = "width: 200px;height: 200px;";
    }
    var iii = 0;
    Comm.upload.render({
      elem: '#' + btnId, //绑定元素
      field: 'file',
      accept: 'images',
      acceptMime: 'image/jpg,image/png,image/JPEG',
      multiple: true, //多图
      number: 5,
      url: config.ossroot,
      before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
      },
      done: function (d) {
        iii++;
        //上传loading
        if ($('#' + divId).children().length > 4) {
          Comm.msg('轮播图最多上传5张');
        } else {
          layer.closeAll('loading'); //关闭loading
          if (iii == 1) {
            layer.msg('上传成功', {
              time: 2000
            });
          }
          var htmlStr = "<div class=\"layui-inline\">";
          htmlStr += "<img class=\"layui-upload-img\" src=\"" + Comm.OSS.getImgUrl(this.data.key) +
            "\" style=\"" + imgSize + "\" data=\"" + this.data.key + "\"/><br/>";
          htmlStr +=
            "<button type=\"button\" class=\"layui-btn layui-btn-xs layui-btn-danger\" onclick=\"$(this).parent().remove()\">删除</button></div>";
          $("#" + imgId).val($("#" + imgId).val() + this.data.key + ",");
          $("#" + divId).append(htmlStr);
        }
      },
      error: function () {
        //请求异常回调
        layer.closeAll('loading'); //关闭loading
        layer.msg('上传失败', {
          time: 2000
        });
      }
    });
  },
  imgHx: function (url, imgId, divId) {
    var htmlStr = "<div class=\"layui-inline\">";
    htmlStr += "<img class=\"layui-upload-img\" src=\"" + Comm.OSS.getImgUrl(url) +
      "\" style=\"max-width: 200px;max-height: 200px;\" data=\"" + url + "\"/><br/>";
    $("#" + imgId).val(url);
    $("#" + divId).append(htmlStr);
  },

  laydateinit: function (e) {
    var c = {
      elem: "#" + $(e).attr("id"),
      type: $(e).attr("type") != undefined && $(e).attr("type") != '' ? $(e).attr("type") : 'date',
      range: $(e).attr("range") != undefined ? true : false,
    }
    if (e.hasAttribute("min")) {
      c.min = $(e).attr("min")
    }
    if (e.hasAttribute("max")) {
      c.max = $(e).attr("max")
    }
    if (e.hasAttribute("format")) {
      c.format = $(e).attr("format");
    }
    if ($(e).val() != "") {
      c.value = $(e).val();
    }
    $(e).attr("type", 'text');
    Comm.laydate.render(c);
  }
}


var $ = null;
//初始化页面
window.onload = function () {
  layui.config({
    base: 'inc/'
  });
  /**
   * 对layui进行全局配置
   */
  layui.use(['table', 'laydate', 'form', 'laytpl', 'layer', 'jquery', 'upload', 'element'], function () {

    //初始化,全局变量 不可污染
    Comm.table = layui.table, Comm.laytpl = layui.laytpl, Comm.form = layui.form, Comm.laydate = layui.laydate, Comm.layer = layui.layer, $ = layui.jquery, Comm.upload = layui.upload;

    /*处理时间选择器*/
    $("input[laydate]").each(function (i, e) {
      Comm.laydateinit(e);
    })

    //处理页面table
    /*search*/
    Comm.search = function (tableid, isJson) {
      var tableid = tableid ? tableid : 'table';
      var w = Comm.GetData("search-form");
      if (isJson) {
        w = {
          conditions: JSON.stringify(w)
        };
      }
      //执行重载
      Comm.table.reload(tableid, {
        page: {
          curr: 1
        }, //重新从第 1 页开始
        where: w
      });
    };

    /*sort*/
    Comm.table.on('sort(table)', function (obj) {
      var p = Comm.GetData("search-form");
      p[obj.field] = obj.type
      Comm.table.reload('table', {
        page: {
          curr: 1
        }, //重新从第 1 页开始
        initSort: obj,
        where: p
      });
    })

    /*--------------------------------------------------------------------------------------------------------*/
    //解决行工具多的时候，显示后点击没效果问题
    $(document).off('mousedown', '.layui-table-grid-down').on('mousedown', '.layui-table-grid-down', function (event) {
      _tableTrCurr = $(this).closest('td');
    });

    $(document).off('click', '.layui-table-tips-main [lay-event]').on('click', '.layui-table-tips-main [lay-event]', function (event) {

      var elem = $(this);
      var tableTrCurr = _tableTrCurr;
      if (!tableTrCurr) {
        return;
      }
      var layerIndex = elem.closest('.layui-table-tips').attr('times');
      // 关闭当前这个显示更多的tip
      layer.close(layerIndex);
      _tableTrCurr.find('[lay-event="' + elem.attr('lay-event') + '"]').first().click();
    });
    /*---------------------------------------------------------------------------------------------------*/
    //处理按钮级权限
    var btnIds = Comm.query('btnIds');
    if (btnIds) {
      btnIds = btnIds.split(',');
      $("#search-form").append('<div class="layui-form-item" id="listbtns"></div>')
      for (var i = 0; i < top.Comm.buttonList.length; i++) {
        var e = top.Comm.buttonList[i];
        if (btnIds.indexOf(e.btnId + '') >= 0) {
          $("#search-form #listbtns").append('<button class="layui-btn layui-btn-' + e.btnType + '" style="background-color: ' + e.btnColor + '" onclick="' + e.btnType + '()">' + e.btnName + '</button>')
        }
      }
    }

    Comm.exec("pageload");
  });
};

function add() {
  layer.msg('请开发人员重写该方法实现', {
    icon: 5
  })
}

var layedit;
layui.use(['layedit', 'layer', 'form', 'jquery'], function () {
  var $ = layui.jquery,
    layer = layui.layer;
  layedit = layui.layedit;
  layedit.set({
    uploadImage: {
      url: config.root + 'file/upload/layedit',
      field: 'file', //上传时的文件参数字段名
      accept: 'image',
      acceptMime: 'image/*',
      exts: 'jpg|png|gif|bmp|jpeg',
      size: 1024 * 10,
      headers: {
        'Authorization': Comm.db("Authorization")
      },
      done: function (data) {}
    },
    //视频上传
    uploadVideo: {
      // url: 'your url',
      // accept: 'video',
      // acceptMime: 'video/*',
      // exts: 'mp4|flv|avi|rm|rmvb',
      // size: 1024 * 10 * 2,
      // done: function (data) {
      //   console.log(data);
      // }
    },
    //文件上传
    uploadFiles: {
      // url: 'your url',
      // accept: 'file',
      // acceptMime: 'file/*',
      // size: '20480',
      // done: function (data) {
      //   console.log(data);
      // }
    },
    //删除回调
    calldel: {
      // url: 'your url',
      // done: function (data) {
      //   console.log(data);
      // }
    },
    autoSync: true,
    facePath: layui.cache.dir, //'http://knifez.gitee.io/kz.layedit/Content/Layui-KnifeZ/',
    devmode: true,
    tool: [
      // 'undo',
      // 'redo',
      // 'code',
      'strong',
      'italic',
      'underline',
      'del',
      'addhr',
      '|',
      'fontFomatt',
      'fontfamily',
      'fontSize',
      'fontBackColor',
      'colorpicker',
      'face',
      '|',
      'left',
      'center',
      'right',
      '|',
      // 'link',
      // 'unlink',
      // 'images',
      'image_alt',
      // 'video',
      // 'attachment',
      // 'anchors',
      '|',
      // 'table',
      'fullScreen',
      'html'
    ],
    // height: '80%'
  });
})